using System;
using System.Collections.Generic;
using System.Drawing;
using System.Resources;
using PluginFrame;

namespace PcrExperimentProject
{
	[Serializable]
	public abstract class PcrExperimentProject : IPcrExperimentProject
	{
		[NonSerialized]
		protected IApplication mApplication;

		[NonSerialized]
		protected ResourceManager mResourceManager;

		[NonSerialized]
		protected IMiscService mMiscService;

		[NonSerialized]
		protected IConfigurationService mConfigurationService;

		[NonSerialized]
		protected IRuleEditorService mRuleEditorService;

		protected List<IPcrCell> mCells;

		protected string mFileName;

		protected string mName;

		protected PcrSystemType mSystemType;

		protected IPcrProgram mPcrProgram;

		protected TemperatureControlType mTemperatureControlType;

		protected double mReactionVolume;

		protected List<int> mAvailableChannels;

		protected List<bool> mIsChannelUsed;

		protected IChannelConfiguration[] mChannelConfigurations;

		protected List<bool> mIsHotLidUsed;

		protected List<IAnalysisParameterConfiguration> mAnalysisParameterConfigurationList;

		protected List<IProjectProperty> mProjectPropertyList;

		protected IProjectItem[] mProjectItems;

		protected Guid mGuid;

		protected double[,] mCrossTalkValue;

		protected IRuleItem mAdvancedRule;

		protected bool mIsUseAdvancedRule;

		protected bool[] mZonePasswordStatus;

		protected string mPassword;

		[NonSerialized]
		protected bool mIsPasswordMatch;

		[NonSerialized]
		protected int mMinRealTimeAmplificationCycle;

		[NonSerialized]
		protected int mMinRealTimeMeltingCycle;

		protected string mRemark;

		protected string mUnit;

		protected string mQuantitativeGreyConlusion;

		protected string mQualitativeGreyConlusion;

		protected string mQuantitativePositiveConlusion;

		protected string mQualitativePositiveConlusion;

		protected string mQuantitativeNegativeConlusion;

		protected string mQualitativeNegativeConlusion;

		protected Color mQuantitativeGreyColor;

		protected Color mQualitativeGreyColor;

		protected Color mQuantitativePositiveColor;

		protected Color mQualitativePositiveColor;

		protected Color mQuantitativeNegativeColor;

		protected Color mQualitativeNegativeColor;

		protected int mTubeCount;

		public int MinRealTimeAmplificationCycle
		{
			get
			{
				return mMinRealTimeAmplificationCycle;
			}
			set
			{
				mMinRealTimeAmplificationCycle = value;
			}
		}

		public int MinRealTimeMeltingCycle
		{
			get
			{
				return mMinRealTimeMeltingCycle;
			}
			set
			{
				mMinRealTimeMeltingCycle = value;
			}
		}

		public bool IsPasswordMatch
		{
			get
			{
				return mIsPasswordMatch;
			}
			set
			{
				mIsPasswordMatch = value;
			}
		}

		public bool[] ZonePasswordStatus
		{
			get
			{
				return mZonePasswordStatus;
			}
			set
			{
				mZonePasswordStatus = value;
			}
		}

		public string Password
		{
			get
			{
				return mPassword;
			}
			set
			{
				mPassword = value;
			}
		}

		public bool IsUseAdvancedRule
		{
			get
			{
				return mIsUseAdvancedRule;
			}
			set
			{
				mIsUseAdvancedRule = value;
			}
		}

		public IRuleItem AdvancedRule
		{
			get
			{
				return mAdvancedRule;
			}
			set
			{
				mAdvancedRule = value;
			}
		}

		public double[,] CrossTalkValue
		{
			get
			{
				return mCrossTalkValue;
			}
			set
			{
				mCrossTalkValue = value;
			}
		}

		public Color QuantitativeGreyColor
		{
			get
			{
				if (mQuantitativeGreyColor == Color.Empty)
				{
					mQuantitativeGreyColor = Color.Black;
				}
				return mQuantitativeGreyColor;
			}
			set
			{
				mQuantitativeGreyColor = value;
			}
		}

		public Color QualitativeGreyColor
		{
			get
			{
				if (mQualitativeGreyColor == Color.Empty)
				{
					mQualitativeGreyColor = Color.Black;
				}
				return mQualitativeGreyColor;
			}
			set
			{
				mQualitativeGreyColor = value;
			}
		}

		public Color QuantitativePositiveColor
		{
			get
			{
				if (mQuantitativePositiveColor == Color.Empty)
				{
					mQuantitativePositiveColor = Color.Black;
				}
				return mQuantitativePositiveColor;
			}
			set
			{
				mQuantitativePositiveColor = value;
			}
		}

		public Color QualitativePositiveColor
		{
			get
			{
				if (mQualitativePositiveColor == Color.Empty)
				{
					mQualitativePositiveColor = Color.Black;
				}
				return mQualitativePositiveColor;
			}
			set
			{
				mQualitativePositiveColor = value;
			}
		}

		public Color QuantitativeNegativeColor
		{
			get
			{
				if (mQuantitativeNegativeColor == Color.Empty)
				{
					mQuantitativeNegativeColor = Color.Black;
				}
				return mQuantitativeNegativeColor;
			}
			set
			{
				mQuantitativeNegativeColor = value;
			}
		}

		public Color QualitativeNegativeColor
		{
			get
			{
				if (mQualitativeNegativeColor == Color.Empty)
				{
					mQualitativeNegativeColor = Color.Black;
				}
				return mQualitativeNegativeColor;
			}
			set
			{
				mQualitativeNegativeColor = value;
			}
		}

		public string QuantitativePositiveConlusion
		{
			get
			{
				return mQuantitativePositiveConlusion;
			}
			set
			{
				mQuantitativePositiveConlusion = value;
			}
		}

		public string QualitativePositiveConlusion
		{
			get
			{
				return mQualitativePositiveConlusion;
			}
			set
			{
				mQualitativePositiveConlusion = value;
			}
		}

		public string QuantitativeNegativeConlusion
		{
			get
			{
				return mQuantitativeNegativeConlusion;
			}
			set
			{
				mQuantitativeNegativeConlusion = value;
			}
		}

		public string QualitativeNegativeConlusion
		{
			get
			{
				return mQualitativeNegativeConlusion;
			}
			set
			{
				mQualitativeNegativeConlusion = value;
			}
		}

		public string QuantitativeGreyConlusion
		{
			get
			{
				return mQuantitativeGreyConlusion;
			}
			set
			{
				mQuantitativeGreyConlusion = value;
			}
		}

		public string QualitativeGreyConlusion
		{
			get
			{
				return mQualitativeGreyConlusion;
			}
			set
			{
				mQualitativeGreyConlusion = value;
			}
		}

		public string Unit
		{
			get
			{
				return mUnit;
			}
			set
			{
				mUnit = value;
			}
		}

		public int TubeCount
		{
			get
			{
				if (mTubeCount <= 0)
				{
					mTubeCount = 1;
				}
				return mTubeCount;
			}
			set
			{
				mTubeCount = value;
			}
		}

		public Guid Guid
		{
			get
			{
				return mGuid;
			}
		}

		public List<IPcrCell> Cells
		{
			get
			{
				return mCells;
			}
		}

		public string Name
		{
			get
			{
				return mName;
			}
			set
			{
				mName = value;
			}
		}

		public IProjectItem[] ProjectItems
		{
			get
			{
				return mProjectItems;
			}
			set
			{
				mProjectItems = value;
			}
		}

		public IChannelConfiguration[] ChannelConfigurations
		{
			get
			{
				return mChannelConfigurations;
			}
		}

		public string Remark
		{
			get
			{
				return mRemark;
			}
			set
			{
				mRemark = value;
			}
		}

		public PcrSystemType SystemType
		{
			get
			{
				return mSystemType;
			}
			set
			{
				mSystemType = value;
			}
		}

		public IPcrProgram PcrProgram
		{
			get
			{
				return mPcrProgram;
			}
			set
			{
				mPcrProgram = value;
			}
		}

		public TemperatureControlType TemperatureControlType
		{
			get
			{
				return mTemperatureControlType;
			}
			set
			{
				mTemperatureControlType = value;
			}
		}

		public double ReactionVolume
		{
			get
			{
				return mReactionVolume;
			}
			set
			{
				mReactionVolume = value;
			}
		}

		public List<bool> IsChannelUsed
		{
			get
			{
				return mIsChannelUsed;
			}
			set
			{
				mIsChannelUsed = value;
				mAvailableChannels = new List<int>();
				for (int i = 0; i < mIsChannelUsed.Count; i++)
				{
					if (mIsChannelUsed[i])
					{
						mAvailableChannels.Add(i);
					}
				}
			}
		}

		public List<int> IsAvailableChannels
		{
			get
			{
				return mAvailableChannels;
			}
		}

		public int AvailableChannelAmount
		{
			get
			{
				return mAvailableChannels.Count;
			}
		}

		public List<IAnalysisParameterConfiguration> AnalysisParameterConfigurationList
		{
			get
			{
				return mAnalysisParameterConfigurationList;
			}
			set
			{
				mAnalysisParameterConfigurationList = value;
			}
		}

		public List<IProjectProperty> ProjectPropertyList
		{
			get
			{
				return mProjectPropertyList;
			}
			set
			{
				mProjectPropertyList = value;
			}
		}

		public string FileName
		{
			get
			{
				return mFileName;
			}
			set
			{
				mFileName = value;
			}
		}

		public override string ToString()
		{
			return mName;
		}

		public abstract IProjectItem CreateProjectItem(int index, string name, int tubeCount);

		public abstract IProjectItem ChangeProjectItemName(int index, string name);

		public virtual void CalculateRealTimeMaxCycleValue()
		{
			mMinRealTimeAmplificationCycle = mPcrProgram.AmplificationDetectionCount;
			mMinRealTimeMeltingCycle = mPcrProgram.MeltingDetectionCount;
			List<int> list = new List<int>();
			IProjectItem[] array = mProjectItems;
			foreach (IProjectItem projectItem in array)
			{
				if (projectItem != null && projectItem.ChannelConfiguration.IsAvailable && projectItem.ChannelConfiguration.IsSelected)
				{
					list.Add(projectItem.ChannelConfiguration.Position);
				}
			}
			foreach (IPcrCell mCell in mCells)
			{
				foreach (int item in list)
				{
					int channelRawDataPoint = mCell.GetChannelRawDataPoint(item);
					int num;
					int num2;
					if (channelRawDataPoint >= mPcrProgram.AmplificationDetectionCount)
					{
						num = mPcrProgram.AmplificationDetectionCount;
						num2 = channelRawDataPoint - num;
					}
					else
					{
						num = channelRawDataPoint;
						num2 = 0;
					}
					if (num < mMinRealTimeAmplificationCycle)
					{
						mMinRealTimeAmplificationCycle = num;
					}
					if (num2 < mMinRealTimeMeltingCycle)
					{
						mMinRealTimeMeltingCycle = num2;
					}
				}
			}
		}

		public virtual void Update()
		{
			mPcrProgram.Update();
		}

		public void SetApplication(IApplication app)
		{
			if (mApplication == null)
			{
				mApplication = app;
				mConfigurationService = (IConfigurationService)mApplication.GetService("ConfigurationService");
				mRuleEditorService = (IRuleEditorService)mApplication.GetService("RuleEditorService");
			}
			if (mPcrProgram != null)
			{
				mPcrProgram.SetApplication(app);
			}
			if (mProjectItems != null)
			{
				IProjectItem[] array = mProjectItems;
				foreach (IProjectItem projectItem in array)
				{
					if (projectItem == null)
					{
						continue;
					}
					projectItem.AnalysisParameterConfiguration.SetApplication(app);
					if (projectItem.TubeAnalysisParameterConfiguration != null)
					{
						foreach (IAnalysisParameterConfiguration item in projectItem.TubeAnalysisParameterConfiguration)
						{
							item.SetApplication(app);
						}
					}
					if (projectItem.TubeMeltingAnalysisParameterConfiguration == null)
					{
						continue;
					}
					foreach (IAnalysisParameterConfiguration item2 in projectItem.TubeMeltingAnalysisParameterConfiguration)
					{
						item2.SetApplication(app);
					}
				}
			}
			if (mAnalysisParameterConfigurationList != null)
			{
				foreach (IAnalysisParameterConfiguration mAnalysisParameterConfiguration in mAnalysisParameterConfigurationList)
				{
					if (mAnalysisParameterConfiguration != null)
					{
						mAnalysisParameterConfiguration.SetApplication(app);
					}
				}
			}
			if (string.IsNullOrEmpty(mUnit))
			{
				mUnit = mConfigurationService.QuantitativeResultUnit;
			}
			if (mAdvancedRule == null)
			{
				mAdvancedRule = mRuleEditorService.CreateRuleObject();
			}
		}

		public bool IsProjectSame(IPcrExperimentProject project)
		{
			if (mName.Equals(project.Name))
			{
				return mGuid.Equals(project.Guid);
			}
			return false;
		}

		public bool IsProjectMatch(IPcrExperimentProject project)
		{
			if (project == null)
			{
				return true;
			}
			int num = mChannelConfigurations.Length;
			IChannelConfiguration[] channelConfiguration2 = project.ChannelConfigurations;
			if (project.PcrProgram != null && !mPcrProgram.IsEqual(project.PcrProgram))
			{
				return false;
			}
			for (int i = 0; i < num; i++)
			{
				IChannelConfiguration channelConfiguration = project.ChannelConfigurations[i];
				if (!channelConfiguration.Content.Equals(mChannelConfigurations[i].Content))
				{
					return false;
				}
			}
			return true;
		}
	}
}
